﻿using System;

namespace CardPlay.Model.ActionModel
{
    public class DelegatingAction : IAction
    {
        public Action OnExecute { get; set; }
        public Action OnReverse { get; set; }

        void IAction.Execute()
        {
            if (OnExecute != null) OnExecute();
        }

        void IAction.Reverse()
        {
            if (OnReverse != null) OnReverse();
        }
    }

    public class DelegatingAction<TState> : IAction
    {
        public TState SavedState { get; set; }

        public Func<TState> OnExecute { get; set; }
        public Action<TState> OnReverse { get; set; }

        void IAction.Execute()
        {
            if (OnExecute != null)
                SavedState = OnExecute();
        }

        void IAction.Reverse()
        {
            if (OnReverse != null)
                OnReverse(SavedState);
        }
    }
}